package com.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 

import com.beans.AddBugBean;
import com.beans.UserBean;
import com.dao.AddBugDAO;
import com.dao.UserDAO;
/** * Servlet implementation class LoginServlet */ 
public class AddBugServlet extends HttpServlet { 
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { 
		try {
			AddBugBean bug = new AddBugBean(); 
			boolean flag = false;
			bug.setDesc(request.getParameter("bug_desc")); 
			bug.setPriority(Integer.parseInt(request.getParameter("bug_prio")));
			bug.setAssignedTo(request.getParameter("bug_assignto"));
			
			flag = AddBugDAO.addbug(bug);
			
			if (flag) {
				HttpSession session = request.getSession(true);
				session.setAttribute("message","Successfully added the bug with ID:"+bug.getBugId());
				response.sendRedirect("success.jsp"); //logged-in page 
			} else 
				response.sendRedirect("bugError.jsp"); //error page
		
		} catch (Throwable theException) { 
			System.out.println(theException); 
		}
	
	}
}
